package com.game.modular.game.playerMatch.domain;

import java.util.Date;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import com.game.config.dao.typeHandler.SetLongHandler;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiParam;
import lombok.*;
import com.fasterxml.jackson.annotation.JsonFormat;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * pvp对局信息(PvpMatch)表实体类
 *
 * @author cxy
 * @since 2024-07-16 18:08:51
 */
@ApiModel("pvp对局信息")
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EqualsAndHashCode(callSuper = true)
@SuppressWarnings("serial")
public class PvpMatch extends Model<PvpMatch> {// swagger2,mybatis-plus
    ///////////////////////////////////////////////////////////////////////////////////////////////////////// 生成实体字段
    @TableId(type = IdType.AUTO)
    @ApiModelProperty("对局id")
    private Long id;

    @ApiParam(required = true)
    @NotNull(message = "参加比赛地图id不能为空")
    @ApiModelProperty("使用的pvp地图")
    private Integer pvpMapId;

    @ApiParam(required = true)
    @NotNull(message = "比赛类型不能为空")
    @ApiModelProperty("比赛类型 0普通,1快速")
    private Integer type;
    public static final Integer PvpMatch_TYPE_NORMAL = 0;
    public static final Integer PvpMatch_TYPE_QUICK = 1;
    public static final Integer PvpMatch_TYPE_QUICK2 = 2;

    @ApiModelProperty("状态 0人数未到齐,1进行中,2结束")
    private Integer status;
    public static final Integer PvpMatch_STATUS_NO_YET = 0;
    public static final Integer PvpMatch_STATUS_YET = 1;
    public static final Integer PvpMatch_STATUS_END = 2;

    @ApiModelProperty("比赛开始时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8")
    private Date startTime;
    
    @ApiModelProperty("比赛结束时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8")
    private Date endTime;

    @TableField(typeHandler = SetLongHandler.class)
    @ApiModelProperty("胜利方 关联游戏账户id")
    private Set<Long>  winnerIds;

    @TableField(typeHandler = SetLongHandler.class)
    @ApiModelProperty(value = "在次对局的玩家id")
    private Set<Long> playerIds;

    @TableField(typeHandler = SetLongHandler.class)
    @ApiModelProperty("加入匹配的玩家id")
    private Set<Long> playerCount;

    @Min(value = 1, message = "不能小于1")
    @ApiModelProperty("开始阈值")
    private Integer startThreshold;
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////////// 序列化版本号
    @TableField(exist = false)
    private static final long serialVersionUID = -99988062609214396L;
    /////////////////////////////////////////////////////////////////////////////////////////////////////////// 获取主键值
    @Override
    public Serializable pkVal() {
        return this.id;
    }
    ///////////////////////////////////////////////////////////////////////////////////////////////////////// 非数据库字段
    /////////////////////////////////////////////////////////////////////////////////////////////////////////    领域业务

    /**
     * 玩家退出对局
     * @param playerId 玩家id
     */
    public void removePlayerId(Long playerId) {
        playerIds.remove(playerId);
    }
    public void addPlayerId(Long playerId) {
        playerIds.add(playerId);
    }
    public void addPlayerCount(Long playerId) {
        playerCount.add(playerId);
    }
    public void removePlayerCount(Long playerId) {
        playerCount.remove(playerId);
    }
    public void addWinnerIds(Long playerId) {
        if (winnerIds==null){
            winnerIds = new HashSet<>();
        }
        winnerIds.add(playerId);
    }
    public void removeWinnerIds(Long playerId) {
        winnerIds.remove(playerId);
    }
}

